import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';

export default (appInfo: EggAppInfo) => {
  const config = {} as PowerPartial<EggAppConfig>;

  // override config from framework / plugin
  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_15807706029';

  // add your egg config in here
  config.middleware = [ 'errorHandler' ];

  // add your special config in here
  const bizConfig = {
    sourceUrl: `https://github.com/eggjs/examples/tree/master/${appInfo.name}`,
  };

  config.validate = {
    convert: true,
  };
  config.security = {
    csrf: {
      enable: false,
    },
  };
  config.cors = {
    origin: 'http://127.0.0.1:5173',
    allowMethods: 'GET,POST',
  };
  config.mysql = {
    client: {
      host: '127.0.0.1',
      port: '3306',
      user: 'root',
      password: '123456',
      database: 'class_system',
    },
    app: true,
  };
  config.jwt = {
    secret: 'bowlCake',
    sign: {
      expiresIn: '60m',
    },
  };
  // the return config will combines to EggAppConfig
  return {
    ...config,
    ...bizConfig,
  };
};
